<%-- 
    Document   : request_user
    Created on : 23/09/2011, 05:20:37 PM
    Author     : Jose
--%>

<%@ page import="PaquetesJL.*" %>
<%@page import="java.sql.ResultSet" %>

<%
    String username=request.getParameter("username");
    String password=request.getParameter("password");
    String tipo_usuario=request.getParameter("tipo_usuario");

    if(username.isEmpty() || password.isEmpty() || tipo_usuario.isEmpty()){
        out.print("Debe llenar todos los campos.");
    }else{
        String sqlServer = pageContext.getServletContext().getInitParameter("sqlServer");
        String databaseName = pageContext.getServletContext().getInitParameter("databaseName");
        String userName = pageContext.getServletContext().getInitParameter("userName");
        String PasswordP = pageContext.getServletContext().getInitParameter("password");
        String Backup = pageContext.getServletContext().getInitParameter("RutaBackup");
        
        byte[] decodedBytes = ConexionBD.decode(PasswordP);
        String decodedPassword = new String(decodedBytes).trim();
        
        ConexionBD Conexion = new ConexionBD(sqlServer, databaseName, userName, decodedPassword, Backup);
        
        Conexion.IniciarConexion();
        ResultSet r=Conexion.EjecutarConsulta("EXEC dbo.CrearUsuario '"+username+"','"+ConexionBD.encode(password) +"',"+tipo_usuario+";");                           
        if(r.next()){
            out.println(r.getString(1));
        }
        Conexion.CerrarConexion(); 
     }
%>